<!DOCTYPE html>
<html>
<head>
    <title>Textbox Input Filtering Example</title>
    <script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
    <p>Select some text in the textbox.</p>
    <form method="post" action="javascript:alert('Form submitted!')" id="myForm">        
        <div>
            <label for="comments">Type a phone number:</label><br>
            <input type="text" id="txtPhone" name="phone" value="">
        </div>
    </form>     
    <script type="text/javascript">
        (function(){

            var textbox = document.getElementById("txtPhone");
            EventUtil.addHandler(textbox, "keypress", function(event){
                event = EventUtil.getEvent(event);
                var target = EventUtil.getTarget(event);
                var charCode = EventUtil.getCharCode(event);
                
                if (!/\d/.test(String.fromCharCode(charCode)) && charCode > 9 && !event.ctrlKey){
                    EventUtil.preventDefault(event);
                }
                
            });
            
        })();
    
    </script>
</body>
</html>
